package com.xln.furns.web;

import com.xln.furns.entity.Manage;
import com.xln.furns.service.ManageService;
import com.xln.furns.service.impl.ManageServiceimpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ManageServlet", value = "/ManageServlet")
public class ManageServlet extends BasicServlet {

    protected void manage_login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        Manage manage = new Manage(null,name,password,null);
        ManageService manageService = new ManageServiceimpl();
        if (manageService.Managelogin(manage) == null){

            request.getRequestDispatcher("/views/manage/manage_login.jsp").forward(request,response);

        }else{
            request.getSession().setAttribute("manage",manage);
            request.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(request,response);
        }
    }
    protected void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.getSession().invalidate();
        response.sendRedirect(request.getContextPath());

    }
}
